<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateModelHasOrderTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('model_has_order', function (Blueprint $table) {
            $table->id();

            $table->unsignedBigInteger('subject_id')->default(0)->comment('模型 ID');
            $table->char('subject_type', 64)->default('')->comment('模型');

            $table->unsignedBigInteger('order_id')->index()->comment('订单 ID');
            $table->tinyInteger('type')->default(1)->comment('用来标注使用类型; 这里的话比如 模型ID 分不同的用户身份(1:代理商 2:团队 3:合伙人)');

            $table->unsignedBigInteger('reward_summary')->default(0)->comment('获得奖励总额 单位分');
            $table->unsignedBigInteger('commission_summary')->default(0)->comment('获得佣金总额 单位分');
            $table->unsignedBigInteger('cultivation_awards_summary')->default(0)->comment('获得培养奖总额 单位分');

            $table->index(['subject_id', 'subject_type']);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('model_has_order');
    }
}
